package com.springboot.cli.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author ding
 */
@RestController
public class IndexController {


    /**
     * 基础web
     */
    @GetMapping("/")
    public Map<String, String> hello() {
        java.net.InetAddress addr = null;
        Map<String, String> res = new HashMap<>();
        try {
            addr = InetAddress.getLocalHost();
        } catch (Exception e) {

        }
        if (addr != null) {
            if (addr.getHostAddress() != null) {
                res.put("hostAddress", addr.getHostAddress());
            }
            if (addr.getHostName() != null) {
                res.put("hostName", addr.getHostName());
            }
        }


        res.put("message", "hello,welcome to index!");
        res.put("args", System.getProperty("startInfo") != null ? System.getProperty("startInfo") : "");
        String ss = UUID.randomUUID().toString();
        res.put("uuid", ss);
        res.put("now", new Date().toString());



        System.out.println("hallow!!" + ss + " " + new Date());

        return res;
    }

    @GetMapping("/get")
    public ContainerInfoFetcher.ContainerInfo get() {
        ContainerInfoFetcher.ContainerInfo info = ContainerInfoFetcher.getContainerInfo();
        return info;
    }
}
